package com.bb.flow.parser.impl;

import com.bb.flow.parser.ObjectCreator;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;


/**
 * @author bigbeard on 2019-12-04
 */
public class ReflectObjectCreatorImpl implements ObjectCreator {

    /**
     * 对象创建器
     *
     * @param classes 类名
     * @return 对象
     * @throws IllegalArgumentException 对象创建异常
     */
    @Override
    public Object instanceBean(String classes) throws ClassNotFoundException, IllegalAccessException,
            InstantiationException, NoSuchMethodException, InvocationTargetException {
        Class<?> clazz = Class.forName(classes);
        Constructor<?> declaredConstructor = clazz.getDeclaredConstructor();
        return declaredConstructor.newInstance();
    }
}
